package com.example.springbootmybatis.service.impl;

import com.example.springbootmybatis.domain.OrderInfo;
import com.example.springbootmybatis.mapper.OrderInfoMapper;
import com.example.springbootmybatis.service.OrderInfoService;
import com.example.springbootmybatis.tool.PageRequest;
import com.example.springbootmybatis.tool.PageResponse;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: springboot_test
 * @description:
 * @author: Mr. Wu
 * @create: 2025-01-09 13:39
 **/
@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Override
    public PageResponse<OrderInfo> orderInfoList(PageRequest<OrderInfo> pageRequest) {
        ////用来设置页面的位置和展示的数据条目数
        PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getPageSize());
        List<OrderInfo> orderInfoLists = orderInfoMapper.getOrderInfoLists();
        //包装Page对象
        PageInfo<OrderInfo> pageInfo = new PageInfo<>(orderInfoLists);
        //声明PageResponse
        PageResponse<OrderInfo> pageResponse = new PageResponse<>();
        //页码和展示数量
        pageResponse.setPageNum(pageRequest.getPageNum());
        pageResponse.setPageSize(pageRequest.getPageSize());
        //返回数据
        pageResponse.setResult(pageInfo.getList());
        //数据总条数
        pageResponse.setTotal(pageInfo.getTotal());
        //总页数
        pageResponse.setPages(pageInfo.getPages());

        return pageResponse;
    }
}
